package com.bbx.taxi.client.Adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.DB.ContactsDB;
import com.bbx.taxi.client.DB.Util.DBcolumns;
import com.bbx.taxi.official.R;

/**
 * 机构列表
 */
public class OrganizationAdapter extends BaseAdapter {
	public final static String ORG_ID="org_id"; 
	public final static String ORG_NAME="org_name"; 
	public final static String ORG_NUM="org_num"; 
	private List<Map<String, String>> list;
	private Activity main;

	public OrganizationAdapter(Activity context,
			List<Map<String, String>> list) {
		this.list = list;
		main = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list != null ? list.size() : 0;
	}

	@Override
	public Map<String, String> getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView,
			ViewGroup parent) {
		ViewHolder viewholder;
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(main);
			convertView = (View) inflater.inflate(
					R.layout.item_organization, null);
			viewholder = new ViewHolder();
			viewholder.tv_name = (TextView) convertView
					.findViewById(R.id.tv_name);
			viewholder.tv_num = (TextView) convertView
					.findViewById(R.id.tv_num);
			convertView.setTag(viewholder);
		} else
			viewholder = (ViewHolder) convertView.getTag();
		viewholder.tv_name.setText(list.get(position).get(ORG_NAME));
		viewholder.tv_num.setText(list.get(position).get(ORG_NUM));
		return convertView;
	}

	public class ViewHolder {
		TextView tv_name, tv_num;
	}

}
